package com.pacy.pacybaseproject.adapters;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.view.menu.MenuAdapter;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.pacy.pacybaseproject.R;
import com.pacy.pacybaseproject.activitys.TravelActivity;
import com.pacy.pacybaseproject.beans.MenuBaseBean;
import com.pacy.pacybaseproject.beans.MenuBean;
import com.pacy.pacybaseproject.events.MainTabEvent;

import org.greenrobot.eventbus.EventBus;

/**
 * @author PACY
 * @date 2024/1/3
 * description:
 */
public class SerBaseMenuAdapter extends BaseQuickAdapter<MenuBaseBean, BaseViewHolder> {
    private RecyclerView recyclerView;
    private GridLayoutManager manager;
    private SerMenuAdapter menuAdapter;
    public SerBaseMenuAdapter() {
        super(R.layout.ser_base_menu_item_view);
    }

    @Override
    protected void convert(BaseViewHolder holder, MenuBaseBean s) {
        holder.setText(R.id.title,s.getTitle());
        recyclerView=holder.getView(R.id.recyclerView);
        manager=new GridLayoutManager(getContext(),4);
        recyclerView.setLayoutManager(manager);
        menuAdapter=new SerMenuAdapter();
        menuAdapter.setNewInstance(s.getMenuBeans());
        recyclerView.setAdapter(menuAdapter);
        menuAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter<?, ?> adapter, View view, int position) {
                Intent intent=new Intent(getContext(),TravelActivity.class);
                Bundle bundle=new Bundle();
                switch (position){
                    case 1:
                        bundle.putInt("initTabPosition",3);
                        intent.putExtras(bundle);
                        getContext().startActivity(intent);
                        break;
                    case 2:
                        bundle.putInt("initTabPosition",2);
                        intent.putExtras(bundle);
                        getContext().startActivity(intent);
                        break;
                    case 3:
                        bundle.putInt("initTabPosition",1);
                        intent.putExtras(bundle);
                        getContext().startActivity(intent);
                        break;
                }

            }
        });

    }
}
